<%= form_for @task,
     :remote => true,
     :method => :put do |f|
 %>
<div class='edit_task'>
  <h6>编辑该任务</h6>
  <form>
  <dl>
    <dt></dt>
    <dd>
      <%= f.text_field :name, :class => :task_name %>
      <%= f.hidden_field :customer_id %>
      <%= f.hidden_field :feed_id %>
      <%= hidden_field_tag "type", params[:type] %>
    </dd>
  </dl>
  <dl>
    <dt>该任务指派给谁？</dt>
    <dd>
      <%= f.select :executor_id, User.active.workmates.collect { |user| [user.nick_name, user.id]} %>
    </dd>
  </dl>
  <dl>
    <dt>何时到期？</dt>
    <dd>
      <%= f.text_field :due_on, :class => :date %>
    <script>
      $('#task_due_on').datepicker({
        showButtonPanel: true
      });
    </script>
    </dd>
  </dl>
  <dl>
    <dt></dt>
    <dd>
      <%= f.check_box :visible_scope, {}, 'everyone', 'only_myself'%> <%= label :task, :visible_scope, '让所有同事可以见到该任务' %>
    </dd>
  </dl>
  <dl>
    <dt>任务类型</dt>
    <dd id='task_type_by_input_<%=@task.id%>' class='task_type_by_input'>
    <%= f.text_field :type_name, :id => "text_task_type_#{@task.id}", :class => :task_type %>
    <%= link_to_function '选择',"$('#task_type_by_select_#{@task.id}').show();$('#task_type_by_input_#{@task.id}').hide()", :title => '从已有的类型中挑选一项', :class => 'task_type_switch task_type_switch_from_select' %>
    </dd>
    <dd id='task_type_by_select_<%=@task.id%>' class='task_type_by_select'>
    <%= select_tag :sel_type_name, task_types, :class => :task_types, :id => "sel_type_name_edit"%>
    <%= link_to_function '输入',"$('#task_type_by_input_#{@task.id}').show();$('#task_type_by_select_#{@task.id}').hide();$('#text_task_type_#{@task.id}').select()", :title => '没有合适的，还是我自己输入吧', :class => 'task_type_switch task_type_switch_from_input' %>
    <script type="text/javascript" charset="utf-8">
      $('#sel_type_name_edit').change(function() {
        $('#text_task_type_<%=@task.id%>').val($(this).val());
      });
      $('#sel_type_name_edit').val("<%=@task.type_name%>");

      //如果文本框的值与下拉选框的值不等，则显示文本框，隐藏下拉选框
      var is_equal = false;
      $('#sel_type_name_edit option').each(function(){
          if($(this).val() == $('#text_task_type_<%=@task.id%>').val()){
              is_equal = true;
          }
      });
      if(!is_equal){
          $('#task_type_by_input_<%=@task.id%>').show();
          $('#task_type_by_select_<%=@task.id%>').hide();
      }
    </script>
    </dd>
  </dl>  
  <div class='clear'></div>
  <hr/>
  <dl>
    <dt></dt>
    <dd>
      <%= submit_tag '保存' %><%= link_to '返回',tasks_url(:type => params[:type]), :remote => true, :method => :get, :class => :button %>
    </dd>
  </dl>
  </form>
</div>
<%end%>